package ee.siimkaspar.subjects.service;

import javax.persistence.Query;

import org.apache.log4j.Logger;
import org.springframework.transaction.annotation.Transactional;

import ee.siimkaspar.subjects.model.Contact;
import ee.siimkaspar.subjects.model.ContactType;

@Transactional
public class ContactService extends BaseService {

	public ContactType getContactType(Integer contactId) {
		try {
			String sql = "select c from Contact c where c.id=:contactId";
			Query q = getEntityManager().createQuery(sql);
			q.setParameter("contactId", contactId);
			Contact c = (Contact) q.getSingleResult();
			return c.getContactType();
		} catch(Exception e) {
			Logger.getLogger(getClass()).error("Error loading contact type. Error msg=" + e.getMessage());
		}
		return null;
	}
}
